const { Model } = require("mongoose");
var mongoose = require("./db");
var Schema = mongoose.Schema;

// 用户表
let UserSchema = new Schema({
  username: String, //用户名
  password: String, //密码
  phone: {
    type: String,
    default: "",
  }, //手机号
  email: {
    type: String,
    default: "",
  }, //邮箱
  sex: {
    type: String,
    default: "",
  }, //性别
  address: {
    type: String,
    default: "",
  }, //住址
  Idcard: {
    type: String,
    default: "",
  }, //身份证件
  status: {
    //状态
    type: Boolean,
    default: true,
  },
  img: {
    type: String,
    default: "../uplate/a.png",
  }, //头像
  real_name: {
    type: String,
    default: "",
  }, //真实姓名
  date_birth: {
    type: Date,
    default: "",
  }, //出生日期
  marital_status: {
    type: String,
    default: "",
  }, //婚姻状态
  nationality: {
    type: String,
    default: "",
  }, //国籍
  native_place: {
    type: String,
    default: "",
  }, //籍贯
  nation: {
    type: String,
    default: "",
  }, //民族
  registration_type: {
    type: String,
    default: "",
  }, //户口性质
  v_mark: {
    type: String,
    default: "",
  }, //微信号
  q_mark: {
    type: String,
    default: "",
  }, //qq号
  emergency_contact: {
    type: String,
    default: "",
  }, //紧急联系人
  emergency_contact_phone: {
    type: String,
    default: "",
  }, //紧急联系人电话
  permanent_address: {
    type: String,
    default: "",
  }, //户口地
  house_address: {
    type: String,
    default: "",
  }, //家庭住址
  leval: {
    type: Number,
    default: 0,
  }, //自关联用户
  user_id: {
    type: mongoose.Types.ObjectId,
    ref: "user",
  },
  EntryMessage_id: [
    {
      type: mongoose.Types.ObjectId,
      ref: "entry",
    },
  ], //关联入职信息
  education_experience_id: [
    {
      type: mongoose.Types.ObjectId,
      ref: "education_experience",
    },
  ], //关联教育信息
  work_experience_id: [
    {
      type: mongoose.Types.ObjectId,
      ref: "work_experience",
    },
  ], //关联工作信息
});
const UserModel = mongoose.model("user", UserSchema);


// 通知公告分类
const noticeClassfySchema = new Schema({
  title: String, // 分类名称
  level: Number, // 分类级别
  noticeId: {
    type: mongoose.Types.ObjectId,
    ref: "notificationfy" // 上一级分类
  },
})
const noticeClassfyModel = mongoose.model('notificationfy', noticeClassfySchema, 'notificationfy')


// 日常工作-通知公告
const NotificationSchema = new Schema({
  title: {
    //标题
    type: String,
    default: "",
  },
  publish: String, // 时间
  content: Array, // 内容
  File: {
    type: String,
    default: "",
  },
  log_file: {
    // 日志文件
    type: Array,
  },
  noticeClassId:{
    type:mongoose.Types.ObjectId,
    ref:'notificationfy'
  }
});
const NotificationModel = mongoose.model(
  "notification",
  NotificationSchema,
  "notification"
);

// 日常工作-图片新闻
const JournalismSchema = new Schema({
  title: {
    //标题
    type: String,
    default: "",
  },
  publish: String, // 时间
  content: Array, // 内容
  File: {
    type: String,
    default: "",
  },
  log_file: {
    // 日志文件
    type: Array,
  },
  title_pic: String, // 新闻图片
});
const JournalismModel = mongoose.model(
  "journalism",
  JournalismSchema,
  "journalism"
);

// 日常工作-我的申请
const ApplySchema = new Schema({
  anumber: {
    // 流程编号
    type: String,
    default: "",
  },
  technological: String, // 流程名称
  department: String, // 发起部门
  aname: String, // 发起人
  date: {
    //申请时间
    type: Date,
    default: new Date(),
  },
  prodepartment: String, // 内容
  daname: {
    // 代办人员
    type: String,
    default: "",
  },
  status: {
    // 状态
    type: String,
  },
  done: {
    type: String,
  },
  dtype: {
    type: String,
  },
});
const applyModel = mongoose.model("applys", ApplySchema, "applys");

// 入职信息
let EntryMessageSchema = new Schema({
  entry_time: {
    //入职时间
    type: Date,
    default: new Date(),
  },
  become_time: {
    //转正日期
    type: Date,
    default: "",
  },
  dimission_time: {
    //离职日期
    type: Date,
    default: "",
  },
  station_id: {
    //关联的职位
    type: mongoose.Types.ObjectId,
    ref: "station",
  },
  Bank_of_account: {
    //银行开户行
    type: String,
    default: "",
  },
  account_name: {
    //开户名
    type: String,
    default: "",
  },
  credit_card_numbers: {
    //银行卡号
    type: String,
    default: "",
  },
  Social_security_card_number: {
    //社保卡号
    type: String,
    default: "",
  },
  Reserve_fund_number: {
    //公积金号
    type: String,
    default: "",
  },
  Work_schedule: {
    //工作排班
    type: String,
    default: "",
  },
  professional_qualifications: {
    //职称等级
    type: String,
    default: "",
  },
  werknemersoort: {
    //员工类型
    type: String,
    default: "",
  },
  start: {
    //工作状态
    type: Boolean,
    default: true,
  },
});
const EntryMessageModel = mongoose.model("entry", EntryMessageSchema);

// 部门
let DepartmentSchema = new Schema({
  name: {
    //部门名称
    type: String,
    default: "",
  },
  leval: Number, //几级列表
  department_id: {
    //自关联
    type: mongoose.Types.ObjectId,
    ref: "department",
  },
  station_id: [
    {
      //关联岗位
      type: mongoose.Types.ObjectId,
      ref: "station",
    },
  ],
});
const DepartmentModel = mongoose.model("department", DepartmentSchema);

// 岗位
let StationSchema = new Schema({
  name: {
    //岗位名称
    type: String,
    default: "",
  },
  status: {
    //状态
    type: Boolean,
    default: "",
  },
  department_id: {
    //关联部门
    type: mongoose.Types.ObjectId,
    ref: "department",
  },
});
const StationModel = mongoose.model("station", StationSchema);

// 教育经历
let education_experienceSchema = new Schema({
  start_time: {
    //开始时间
    type: Date,
    default: "",
  },
  end_time: {
    //结束时间
    type: Date,
    default: "",
  },
  school_name: {
    //学校名称
    type: String,
    default: "",
  },
  specialty: {
    //专业
    type: String,
    default: "",
  },
  education_background: {
    //学历
    type: String,
    default: "",
  },
});
const education_experienceModel = mongoose.model(
  "education_experience",
  education_experienceSchema
);

// 工作经历
let work_experienceSchema = new Schema({
  start_time: {
    //开始时间
    type: Date,
    default: "",
  },
  end_time: {
    //结束时间
    type: Date,
    default: "",
  },
  danwei_name: {
    //单位名称
    type: String,
    default: "",
  },
  bumen: {
    //部门
    type: String,
    default: "",
  },
  workmain: {
    //工作内容
    type: String,
    default: "",
  },
  whygoaway: {
    //离职原因
    type: String,
    default: "",
  },
});
const work_experienceModel = mongoose.model(
  "work_experience",
  work_experienceSchema
);

// 日计划
const RiplanSchema = new Schema({
  dayindex: {
    //编号
    type: String,
    default: "",
  },
  title: {
    //主题
    type: Object,
    default: {},
  },
  plantype: {
    //计划类型
    type: String,
    default: "",
  },
  planstate: {
    //计划状态
    type: Number,
    default: 0,
  },
  organizationperson: {
    //编制人员
    type: String,
    default: "",
  },
  organizationdepartment: {
    //编制部门
    type: String,
  },
  organizationdata: {
    //编制日期
    type: Date,
    default: "",
  },
  dutyperson: {
    //负责人
    type: String,
    default: "",
  },
  jionpeople: {
    //参与人
    type: String,
    default: "",
  },
  organizationdata: {
    //编制日期
    type: Date,
    default: "",
  },
  startdate: {
    //开始日期
    type: Date,
    default: "",
  },
  enddata: {
    //结束日期
    type: Date,
    default: "",
  },
  sharewho: {
    //将计划共享给谁
    type: Array,
    default: [],
  },
});
const RiplanModel = mongoose.model("riplan", RiplanSchema);


// 资料类别
let MeansCateSchema = new Schema({
  name: {//资料分类名称
    type: String,
    default: ''
  },
  level: {//资料分类级别
    type: Number,
    default: ''
  },
  status: { //状态
    type: Boolean,
    default: false
  },
  meanscate_id: { //关联子资料分类
    type: mongoose.Types.ObjectId,
    ref: 'meanscate'
  }
})
const MeansCateModel = mongoose.model('meanscate', MeansCateSchema)

// 资料信息
let MeansInfoSchema = new Schema({
  MeansSelfCate: {//所属别类
    type: mongoose.Types.ObjectId,
    ref: 'meanscate'
  },
  MeansSelfName: {//文档名称
    type: String,
    default: ''
  },
  MeansSelfHandle: {//上传人员
    type: String,
    // ref: 'user',
    default: '',
  },
  MeansSelfTime: {//上传时间
    type: Date,
    default: ''
  },
  ShareForWho: {//共享给谁
    type: String,
    default: ''
  },
})
const MeansInfoModel = mongoose.model('meansinfo', MeansInfoSchema)



// MeansInfoModel.create([
//   {
//     MeansSelfCate: '63e2344daa920682338a5792',
//     MeansSelfName: '人事调整',
//     MeansSelfHandle: '张妍',
//     MeansSelfTime: '2021-04-29 11:25:39',
//     ShareForWho: '',
//   }
// ])


// MeansCateModel.create([
//    { name: '文档中心',
//   level: 0,
// },
// ])


// MeansCateModel.create([
//    { name: '人事制度',
//   level: 1,
// meanscate_id:'63e233e517d29590088713bf'
// },
//  { name: '营销制度',
//   level: 1,
// meanscate_id:'63e233e517d29590088713bf'
// },
//  { name: '产品资料',
//   level: 1,
// meanscate_id:'63e233e517d29590088713bf'
// },
//  { name: '工作笔记',
//   level: 1,
// meanscate_id:'63e233e517d29590088713bf'
// },
// ])



// RiplanModel.create([
//   {
//     dayindex: "RJH2021040007",
//     title: { "2021年4月8日工作计划": "123" },
//     plantype: "个人计划",
//     planstate: 0,
//     organizationperson: "王子润",
//     organizationdepartment: "经营部",
//     organizationdata: "2021.4.8",
//     dutyperson: "王子润",
//     jionpeople: "王子润",
//     startdate: "2021.4.8",
//     dutyperson: "2021.4.8",
//     sharewho: ['陈凯明', '张研'],
//   },
// ]);


// UserModel.create([
//   {
//     username:'admin',
//     password:'admin123',
//     phone:'15231091125',
//     email:'3308884369@qq.com',
//     sex:'男',
//     address:'河北省邯郸市',
//     Idcard:'13043020030713333',
//     EntryMessage_id:['63e1b8eb8c1320710ad0b762'],
//     education_experience_id:['63e1b4984f9f640ecb8ad039','63e1b4984f9f640ecb8ad03a','63e1b4984f9f640ecb8ad038'],
//     work_experience_id:['63e0adc7597b0000c80026fe']
//   }
// ])

// EntryMessageModel.create([
//   {
//     entry_time:'2023.1',
//     station_id:'63e1b89e4670fa152c3ef7ba',
//   },
//   {
//     entry_time:'2023.5',
//     station_id:'63e1b89e4670fa152c3ef7bb',
//   }
// ])

// StationModel.create([
//   {
//     name:'财务部部长',
//     status:true,
//     department_id:'63e1b856b0675198000dc890'
//   },
//   {
//     name:'总裁',
//     status:true,
//     department_id:'63e1b856b0675198000dc892'
//   },
//   {
//     name:'市场部部长',
//     status:true,
//     department_id:'63e1b856b0675198000dc891'
//   },
//   {
//     name:'财务部副组长',
//     status:true,
//     department_id:'63e1b856b0675198000dc890'
//   },
//   {
//     name:'市场部副组长',
//     status:true,
//     department_id:'63e1b856b0675198000dc891'
//   }
// ])

// DepartmentModel.create([{
//   name:'财务办',
//   leval:0,
//   // department_id:'63e0bd9b8dc2a2896b3508b3',
//   station_id:[]
// },
// {
//   name:'市场办',
//   leval:0,
//   // department_id:'63e0bd9b8dc2a2896b3508b4',
//   station_id:[]
// },
// {
//   name:'总裁办',
//   leval:0,
//   // department_id:'63e0bd9b8dc2a2896b3508b4',
//   station_id:['63dca225fbf0b95bdb99deb3']
// }])

// education_experienceModel.create([
//     {
//       start_time:'2008.6',
//       end_time:'2012.7',
//       school_name:"邯郸市实验小学",
//       specialty:'学生',
//       education_background:'小学'
//     },
//     {
//       start_time:'2012.9',
//       end_time:'2015.7',
//       school_name:"邯郸市实验中学",
//       specialty:'学生',
//       education_background:'中学',
//     },
//     {
//       start_time:'2015.9',
//       end_time:'2018.7',
//       school_name:'邯郸市第一中学',
//       specialty:'学生',
//       education_background:'高中'
//     }
//   ])

// work_experienceModel.create([
//   {
//     start_time:'2019.5',
//     end_time:'2021.5',
//     danwei_name:'飞腾有限公司',
//     bumen:'财务部',
//     workmain:'公司报账，报销，税收',
//     whygoaway:'工资原因'
//   }
// ])

module.exports = {
  UserModel,
  NotificationModel,
  noticeClassfyModel,
  JournalismModel,
  applyModel,
  EntryMessageModel,
  DepartmentModel,
  StationModel,
  education_experienceModel,
  work_experienceModel,
  RiplanModel,
  MeansCateModel,
  MeansInfoModel
};
